package com.beverages.commodities.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beverages.commodities.common.Result;
import com.beverages.commodities.entity.Commodities;
import com.beverages.commodities.entity.Toppings;
import com.beverages.commodities.service.IToppingsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/customer/toppings")
public class ToppingsController {

    @Resource
    private IToppingsService toppingsService;

    @ApiOperation(
            value = "获取小料",
            notes = "必须传参：\n" +
                    "toppingsIds   (List<Integer>), 无默认值，如果为空，则要传空集合 []\n",
            response = Result.class,
            tags = {"获取小料"}
    )
    @GetMapping("/list")
    public Result getToppingsByIds(@RequestParam("toppingsIds") List<Integer> toppingsIds){
        return Result.success(toppingsService.getToppingsByIds(toppingsIds));
    }

    @ApiOperation(
            value = "列出所有小料",
            notes = "不用传参\n",
            response = Result.class,
            tags = {"列出所有小料"}
    )
    @GetMapping("/display")
    public Result getAllToppings(){
        QueryWrapper<Toppings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("whether_to_list",1);
        return Result.success(toppingsService.list(queryWrapper));
    }

    @ApiOperation(
            value = "列出所有小料，返回原始数据",
            notes = "不用传参\n",
            response = Result.class,
            tags = {"列出所有小料，返回原始数据"}
    )
    @GetMapping("/display/native")
    public List<Toppings> getAllNativeToppings(){
        QueryWrapper<Toppings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("whether_to_list",1);
        return toppingsService.list(queryWrapper);
    }
}
